import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from './utils/axios';
import './components/vant'
import VueSocketIO from 'vue-socket.io'
import SocketIO from 'socket.io-client'
Vue.config.productionTip = false;
Vue.use(new VueSocketIO({
  debug: false,
  connection: 'http://localhost:3000/',
}));
// import VueAMap from 'vue-amap'
import {
  Button,
  Cell,
  CellGroup,
  Checkbox,
  Collapse, 
  CollapseItem,
  Dialog,
  Empty ,
  Field,
  Form,
  Icon,
  ImagePreview,
  Image,
  Loading,
  Lazyload,
  List,
  NavBar,
  Picker ,
  Popup,
  Popover ,
  PullRefresh,
  RadioGroup,
  Radio,
  Sticky,
  Switch,
  Swipe,
  SwipeItem,
  SwipeCell,
  Search,
  Sidebar, 
  SidebarItem,
  Uploader,
  Tag,
  Tab,
  Tabs,
  Toast,
  Tabbar,
  TabbarItem,
} from 'vant';

Vue.use(Button);
Vue.use(Cell);
Vue.use(CellGroup);
Vue.use(Checkbox);
Vue.use(Collapse);
Vue.use(CollapseItem);
Vue.use(Dialog);
Vue.use(Form)
Vue.use(Field);
Vue.use(Icon);
Vue.use(Image);
Vue.use(ImagePreview);
Vue.use(List);
Vue.use(Loading);
Vue.use(Lazyload);
Vue.use(NavBar);
Vue.use(Search);
Vue.use(PullRefresh );
Vue.use(Radio)
Vue.use(RadioGroup)
Vue.use(Tag);
Vue.use(Tab);
Vue.use(Tabs)
Vue.use(Toast);
Vue.use(Tabbar);
Vue.use(TabbarItem);
Vue.use(Picker );
Vue.use(Popup);
Vue.use(Popover);
Vue.use(Sticky);
Vue.use(Switch);
Vue.use(Swipe);
Vue.use(SwipeItem);
Vue.use(SwipeCell);
Vue.use(Sidebar);
Vue.use(SidebarItem);
Vue.use(Uploader)
Vue.use(Empty)
Vue.prototype.$axios = axios; // 将api挂载到vue的原型上
Vue.prototype.$bus = new Vue(); // bus

Toast.setDefaultOptions({ duration: 2000 })
Dialog.setDefaultOptions({ confirmButtonColor: '#1D2B8E' })

Vue.config.productionTip = false

// 一进页面就设置token
// axios.post('/api/notary/auth', {
//   "authKey": "oQFz0Ml/x1HlUp/TbP8nkA==",
//   "authSecret": "G6H/o9ws3Lew6FZI1lF85eiIDvU4SktCburI2yCq2HG9INqTrY67+1sqlUfKBj87"
// }).then(res => {
//   axios.defaults.headers.common['token'] = res.data;
// });
const search = location.search.substr(1).split('&');
const searchObj = {};
search.forEach((item) => {
  const i = item.split('=');
  searchObj[i[0]] = i[1];
})

const pa = searchObj.pa;
const identity = searchObj.identity;
if (pa && identity) {
  getSeId().then((res) => {
    if (res.code === 200) {
      const pData = decryptByDES(res.data.pData, step1Key);
      const seId = toJson(pData).seId;
      const secretK = encryptByDES('seId=' + seId, step2Key)
      getSecretK(secretK).then((res) => {
        if (res.code === 200) {
          const pData2 = decryptByDES(res.data.pData, step2Key);
          const secretK = toJson(pData2).secretK;
          const key = encryptByDES('seId=' + seId + '&pa=' + pa + '&identity=' + identity, secretK);

        }
      })
    }
  })
}


new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')